package controller

import (
	"context"
	pb "gitee.com/micro-services/protocol/hotel/api"
	log "github.com/sirupsen/logrus"
	"micro.hotel.client/ao"
	"micro.hotel.client/plugins"
)

type NoticeController struct{}

func (n *NoticeController) CreateNotice(ctx context.Context, r *pb.APICreateNoticeReq, w *pb.APICreateNoticeRsp) error {
	span, md, spanCtx := plugins.TracerContext(ctx, "CreateNotice")

	rsp, err := ao.CreateNotice(spanCtx, r)
	if err != nil {
		log.Printf("error:%+v", err)
		plugins.TracerErrorInfo(span, "go.micro.api.hotel.CreateNotice", md, r, w, rsp, err)
		return err
	}

	w.RetCode = rsp.RetCode
	w.Msg = rsp.Msg

	plugins.TracerFinish(span, "go.micro.api.hotel.CreateNotice", md, r, w)
	return nil
}

func (n *NoticeController) GetNoticeInfo(ctx context.Context, r *pb.APIGetNoticeInfoReq, w *pb.APIGetNoticeInfoRsp) error {
	span, md, spanCtx := plugins.TracerContext(ctx, "GetNoticeInfo")

	rsp, err := ao.GetNoticeInfo(spanCtx, r)
	if err != nil {
		log.Printf("error:%+v", err)
		plugins.TracerErrorInfo(span, "go.micro.api.hotel.GetNoticeInfo", md, r, w, rsp, err)
		return err
	}

	w.NoticeContent = rsp.NoticeContent

	plugins.TracerFinish(span, "go.micro.api.hotel.GetNoticeInfo", md, r, w)
	return nil
}

func (n *NoticeController) DeleteNotice(ctx context.Context, r *pb.APIDeleteNoticeReq, w *pb.APIDeleteNoticeRsp) error {
	span, md, spanCtx := plugins.TracerContext(ctx, "DeleteNotice")

	rsp, err := ao.DeleteNotice(spanCtx, r)
	if err != nil {
		log.Printf("error:%+v", err)
		plugins.TracerErrorInfo(span, "go.micro.api.hotel.DeleteNotice", md, r, w, rsp, err)
		return err
	}

	w.RetCode = rsp.RetCode
	w.Msg = rsp.Msg

	plugins.TracerFinish(span, "go.micro.api.hotel.DeleteNotice", md, r, w)
	return nil
}
